#pragma once

#include "IMesh.h"
#include <string>
#include <vector>
#include <d3d9.h>
#include "BoundingVolume.h"


class CGraphicsController;
struct CIWFMeshVertex;
class CFileIWF;
class CTextureGroup;

class IWFFileMesh : public IMesh
{
private:
   CGraphicsController& m_graphicsController;
   std::vector<D3DMATERIAL9> m_materials;
   std::vector<IDirect3DTexture9*> m_textures;
   std::vector<CTextureGroup*> m_textureGroups;
   std::vector<CIWFMeshVertex*> m_vertices;
   IDirect3DVertexBuffer9* m_vertexBuffer;

   AABoundingBox m_boundingBox;

public:
   IWFFileMesh(CGraphicsController& graphicsController, 
               const std::wstring& fileName);
   ~IWFFileMesh(void);

   void render();

   const AABoundingBox& getModelSpaceBoundingBox() const {return m_boundingBox;}

private:
   void processMeshes(const CFileIWF& sceneFile);

   CTextureGroup* findTextureGroup(long textureIdx);

   void buildBuffers();

   void buildVertexBuffer();

   void calculateBoundingBox();
};
